package com.itheima.Test;

import java.util.Calendar;

public class Test005 {
    public static void main(String[] args) throws Exception {
        //用程序判断2018年2月14日是星期几
        Calendar c = Calendar.getInstance();
        // //将给定的日历字段设置到Calendar对象中
        c.set(Calendar.YEAR, 2018);
        c.set(Calendar.MONTH, 1);
        c.set(Calendar.DAY_OF_MONTH, 14);
        //设置年
        int i = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);
        //设置星期
        char week = getWeek(c.get(Calendar.DAY_OF_WEEK));
        //输出结果
        System.out.println(i + "年" + month + "月" + day + "日是星期" + week);
    }


    public static char getWeek(int a) {
        char[] c = {' ', '日', '一', '二', '三', '四', '五', '六'};
        return c[a];
    }
}

